---

- name: PrestaShop | Installing dependencies
  apt:
    pkg: "{{ item }}"
    state: present
  with_items: "{{ prestashop_required_libs }}"

- name: PrestaShop | Download PrestaShop binaries
  get_url:
    url: "{{ prestashop_url }}"
    dest: "/tmp/{{ prestashop_package }}"
  register: download_prestashop

- name: PrestaShop | Create installation path
  file:
    path: "{{ prestashop_install_path }}"
    state: directory
    owner: "{{ prestashop_user }}"
    group: "{{ prestashop_group }}"

- name: PrestaShop | Extract PrestaShop in the installation path (1/2)
  unarchive:
    copy: no
    src: "/tmp/{{ prestashop_package }}"
    dest: "{{ prestashop_install_path }}"
    owner: "{{ prestashop_user }}"
    group: "{{ prestashop_group }}"
  when: download_prestashop|changed
  tags:
    skip_ansible_lint

- name: PrestaShop | Extract PrestaShop in the installation path (2/2)
  unarchive:
    copy: no
    src: "{{ prestashop_install_path }}/prestashop.zip"
    dest: "{{ prestashop_install_path }}"
    owner: "{{ prestashop_user }}"
    group: "{{ prestashop_group }}"
  when: download_prestashop|changed
  tags:
    skip_ansible_lint

- name: PrestaShop | Execute installation script
  command: >
    chdir={{ prestashop_install_script_path }} php {{ prestashop_install_script_file }}
    --language={{ prestashop_language }}
    --timezone={{ prestashop_timezone }}
    --domain={{ prestashop_domain }}
    --db_server={{ prestashop_db_server }}
    --db_name={{ prestashop_db_name }}
    --db_user={{ prestashop_db_user }}
    --db_password={{ prestashop_db_pwd }}
    --db_clear={{ prestashop_db_clear }}
    --prefix={{ prestashop_db_prefix }}
    --engine={{ prestashop_db_engine }}
    --name={{ prestashop_name }}
    --activity={{ prestashop_activity }}
    --country={{ prestashop_country }}
    --firstname={{ prestashop_firstname }}
    --lastname={{ prestashop_lastname }}
    --email={{ prestashop_admin_email }}
    --password={{ prestashop_admin_pwd }}
    --license={{ prestashop_show_license }}
    --newsletter={{ prestashop_newsletter }}
  when: download_prestashop|changed
  tags:
    skip_ansible_lint

- name: PrestaShop | Set owner to created files
  file:
    dest: "{{ prestashop_install_path }}"
    owner: "{{ prestashop_user }}"
    group: "{{ prestashop_group }}"
    recurse: yes

- name: PrestaShop | Removing installation stuff
  file:
    path: "{{ prestashop_install_path }}/{{ item }}"
    state: absent
  with_items:
    - "prestashop.zip"
    - "install/"
    - "docs/"
    - "README.md"
    - "INSTALL.txt"
    - "Install_PrestaShop.html"
    - "LICENSES"

- name: PrestaShop | Move default admin folder
  command: "mv {{ prestashop_default_backend_path }} {{ prestashop_new_backend_path }}"
  when: download_prestashop|changed
